// Copyright (c) <2010> <Playdead>
// This file is subject to the MIT License as seen in the trunk of this repository
// Maintained by: <Kristian Kjems> <kristian.kjems+UnitySVN@gmail.com>

// This script includes menu items for common SVN operations


#define SVN_ENABLED
#define SVN_OBJECT_ACTION_ENABLED
#if (SVN_ENABLED)
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using SVNIntegrationNameSpace;
using CommandLineExecution;

public class SVNMenuItems : ScriptableObject
{
#if(SVN_OBJECT_ACTION_ENABLED)

    static IEnumerable<string> GetAssetPathsOfSelected()
    {
        IEnumerable<string> selectedAssets =
            from go in Selection.gameObjects
            let assetPath = SVNUtility.GetAssetPath(go)
            select assetPath;
        return selectedAssets.Distinct();
    }

    [MenuItem("SVN/Get Lock %L")]
    public static void SVNGetLockOnSelected()
    {
        //foreach (var assetIt in GetAssetPathsOfSelected().ToArray())
        //{
        //    Debug.Log("Lock: " + assetIt);
        //}
        SVNCommands.instance.SVNGetLock(GetAssetPathsOfSelected().ToArray(), false);
    }

    [MenuItem("CONTEXT/GameObject/GetLock")]
    static void SVNGetLockOnSelectedContext(MenuCommand command)
    {
        SVNCommands.instance.SVNGetLock(GetAssetPathsOfSelected().ToArray());
    }

    [MenuItem("SVN/Bypass Revision %K")]
    public static void SVNBypassLockOnSelected()
    {
        SVNCommands.instance.SVNBypassRevision(GetAssetPathsOfSelected().ToArray());
    }

    [MenuItem("CONTEXT/GameObject/Bypass Revision")]
    public static void SVNBypassLockOnSelectedContext()
    {
        SVNCommands.instance.SVNBypassRevision(GetAssetPathsOfSelected().ToArray());
    }
#endif


    [MenuItem("SVN/Refresh")]
    public static void SVNRefresh()
    {
        SVNCommands.instance.UpdateSVNStatus();
    }

    [MenuItem("SVN/Update")]
    public static void SVNUpdate()
    {
        SVNCommands.instance.SVNUpdate();
    }

    //[MenuItem("SVN/Test SVN")]
    public static void SVNTest()
    {
    }

    //[MenuItem("SVN/Diff Selection")]
    public static void SVNDiff()
    {

    }



}
#endif